<?php
/**
 * @package user
 * @version $Id: AdminPreload.class.php 841 2008-02-06 16:27:01Z mikhail.miguel $
 */

if (!defined('XOOPS_ROOT_PATH')) exit();

class User_AdminPreload extends XCube_ActionFilter
{
	function preBlockFilter()
	{
		$this->mRoot->mDelegateManager->add('Legacy.Event.ThemeSettingChanged', 'User_AdminPreload::doThemeSettingChanged');
	}
	
	function doThemeSettingChanged($mainTheme, $selectableThemes)
	{
		$root =& XCube_Root::getSingleton();
		$db =& $root->mController->mDB;
		$table = $db->prefix('users');
		
		$mainTheme = $db->quoteString($mainTheme);
		
		$t_conds = array();
		$t_conds[] = "theme <> " . $db->quoteString('');
		foreach ($selectableThemes as $theme) {
			$t_conds[] = "theme <> " . $db->quoteString($theme);
		}
		
		$sql = "UPDATE ${table} SET theme=${mainTheme} WHERE " . join(' AND ' , $t_conds);

		$db->query($sql);
	}
}

?>